#!/usr/bin/perl 
use DBI;
use CGI;
use TTraker;

my $form_ref = parse_input();
print_header();
initialize_dbi();

my %FORM_DATA = ();
%FORM_DATA = %$form_ref; 
my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job_id = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $start = $FORM_DATA{'startDate'};

my %updates= ();
foreach $key (keys %FORM_DATA) {
  if ($key =~ /^payroll_data_/ && $FORM_DATA{$key} ne "" ) {
    $id_str = $key;
    $id_str =~ s/payroll_data_//;
    ($pay_cat,$id_num) = split /_/, $id_str;
    $hrs = $FORM_DATA{$key};
    if ( not exists $updates{$id_num} ) {		
	    $updates{$id_num}=1;
	 }   
#    print "$id_str, $pay_cat, $id_num, $hrs <br/>";   
#    print "update_payroll_hours ($pay_cat, $id_num, $hrs)<br>";
    update_payroll_hours ($pay_cat, $id_num, $hrs);
  } elsif ($key =~ /^task_/) {
    # do not print tasks that have no value
  } else {   
#   print "KEY: $key - $FORM_DATA{$key}<br/>";   
  } 
}
my @Kes = keys %updates;
my @kes = sort @Kes;
foreach $key (@kes) {
#	print "Updating $key <br>";
   update_payroll_total_hours ( $key);
}     

& trak_04_emp_log_in;

db_disconnect();

##################### SUBROUTINES FOLLOW  #####################


sub trak_04_emp_log_in
{
print <<ENDHEADER;

<html>
<head>
<link rel="stylesheet" type="text/css" href="${css_ref}trak.css" />
<script type="text/javascript" src="${js_ref}trak.js"></script>
<title>trak_01_emp_num.html NO NUM</title>
</head>
<body onload="startTime()">
<h2><center>${banner}</center></h2>
<hr/>
<div id="clock"></div>
<div id="box1">
   &nbsp&nbsp&nbsp&nbsp&nbsp Employee ID: <br/><br/>
</div> 
<form id="box2" autocomplete="off" name="empID" action="${cgi_ref}trak_01_emp_log_in.pl" method="post">
   <input type="text" name=empID />&nbsp&nbsp
   <input type="submit" value="Log Into system">
</form>

</body>
</html>

ENDHEADER
}

